﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SpeakerRecognition
{
    /// <summary>
    /// Class for computing the Log of the Energy 
    /// </summary>
    public class LogEnergyMagnitudeCommand : ICommand
    {
        //************************  Private Fields  *******************************// 
        private double[] inputData;
        private double[] outPutData;
        private bool withPowerOfTwo = true;
        //************************  Constructors    *******************************// 
        public LogEnergyMagnitudeCommand()
        {
        }
        //************************  Public Properties  ****************************// 
        public double[] InputData
        {
            get { return inputData; }
            set { inputData = value; }
        }

        public double[] OutPutData
        {
            get { return outPutData; }
            set { outPutData = value; }
        }

        public bool WithPowerOfTwo
        {
            get { return withPowerOfTwo; }
            set { withPowerOfTwo = value; }
        }
        //************************  Public Methods  ****************************// 
        #region ICommand Members

        public void execute()
        {
            outPutData = new double[inputData.Length];
            for (int i = 0; i < inputData.Length; i++)
            {   // calculate the log of the magnitude of the energy
                if (inputData[i] == 0.0)
                {
                    outPutData[i] = 0.0;
                    continue;
                }
                if (withPowerOfTwo)
                    outPutData[i] = Math.Log10(inputData[i] * inputData[i]);     
                else
                    outPutData[i] = Math.Log10(inputData[i]);
            }
        }
        #endregion
    }
}